(in-package :context-indexing)

(defun nvector+ (&rest vectors)
  (apply #'map-into1 #'+ vectors))

(defun vector- (&rest vectors)
  (apply #'map 'vector #'- vectors))

(defun scale (vector scalar)
  (map 'vector (op * _ scalar) vector))

(defun nscale (vector scalar)
  (map-into1 (op * _ scalar) vector))
  
(defun nvector+* (a b scalar)
  (nvector+ a (scale b scalar)))
  
(defun euclidian-distance (a b)
  (declare #.*standard-optimize-settings*)
  (sqrt (sum (op expt (- _ _) 2) a b)))

(defun l2-norm (vector)
  (sqrt (sum (op expt _ 2) vector)))

(defun nnormalize (vector)
  (nscale vector (/ (l2-norm vector))))
